package 广州大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 武汉大学.WhuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GZu {
    public static void main(String[] args) throws IOException {
        GZuBean gZuBean = null;
        List<GZuBean> gZuBeans = new ArrayList<>();
        String Url = "http://jd.gzhu.edu.cn/yjsjy/dsjs.htm";
        String attr2 = null;
        String info = null;
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
        for (Element elementsByClass : post.getElementsByClass("sy-tzgg-con")) {
            for (Element element : elementsByClass.getElementsByTag("ul")) {
                for (Element li : element.getElementsByTag("li")) {
                    gZuBean = new GZuBean();
                    for (Element a : li.getElementsByTag("a")) {
                        gZuBean.setT_name(a.text());//name
                        attr2 = a.attr("href").substring(3, a.attr("href").length());
                        Connection connect1 = Jsoup.connect("http://jd.gzhu.edu.cn/" + attr2);
                        Document post1 = connect1.post();
                        String text = post1.getElementsByTag("p").text();
                        info = text.replace("数字广大 | English", "");
                        String replace = info.replace(" ", "");
                        gZuBean.setInfo(replace);
                        gZuBeans.add(gZuBean);
                    }

                }

            }

        }
        EasyExcel.write("src/Gzu.xlsx", GZuBean.class).sheet("user").doWrite(gZuBeans);
    }
}